package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo3 {
    public static void main(String[] args) throws  SQLException {
        Connection connection = DBUtil.getConnection();
        Statement statement = connection.createStatement();
        Scanner sc = new Scanner(System.in);
        String username, password;
        System.out.println("请输入用户名：");
            username = sc.nextLine();
            if (!username.trim().equals("Tony")) {
                System.out.println("用户名不存在，请重新输入！");
            } else {
                System.out.println("请输入原密码：");
                while (true) {
                    password = sc.nextLine();
                    if (!password.trim().equals("123456")) {
                        System.out.println("密码错误，请重新输入！");
                    } else {
                        System.out.println("正在删除用户信息...");
                        String sql = "delete from userinfo where username='" + username + "'";
                        int i = statement.executeUpdate(sql);
                        if (i > 0) {
                            System.out.println("删除成功！");
                            break;
                        } else {
                            System.out.println("删除失败！");
                        }
                    }
                }

            }
        connection.close();
    }

}

